#ifndef DMDEF_H
#define DMDEF_H

#include <array>
#include <cmath>


/*!
 * @brief 行业标准
 */

// Label

#define LABEL_ON                "ON"
#define LABEL_OFF               "OFF"

#define LABEL_DEVICE_LIST       "Device List"
#define LABEL_SEARCH            "Search"
#define LABEL_CONNECTED         "Connected"
#define LABEL_DISCONNECT        "Disconnect"
#define LABEL_HID_V_ID          "V_ID:"
#define LABEL_HID_P_ID          "P_ID:"
#define LABEL_HID_U_ID          "U_ID:"
#define LABEL_SERIAL_PORT       "PORT:"
#define LABEL_SERIAL_BAUD_RATE  "BAUD:"

#define LABEL_SCENE             "Scene"
#define LABEL_SCENE_NAME        "Name"
#define LABEL_CURRENT_SCENE     "Current"
#define LABEL_LOAD              "Load"
#define LABEL_SAVE              "Save"
#define LABEL_IMPORT            "Import"
#define LABEL_EXPORT            "Export"
#define LABEL_IMPORT_ALL        "Import All"
#define LABEL_EXPORT_ALL        "Export All"

#define LABEL_DEVICE_INFO       "Device Info"
#define LABEL_DEVICE_ID         "Device Id"
#define LABEL_DEVICE_NAME       "Device Name"
#define LABEL_DSP_VERSION       "DSP Version"
#define LABEL_MCU_VERSION       "MCU Version"
#define LABEL_BOOT_VERSION      "Boot Version"
#define LABEL_INPUT_NAME        "Input"
#define LABEL_OUTPUT_NAME       "Output"
#define LABEL_CHANNEL_NAME      "Update Channel Name"

#define LABEL_INPUT_GROUP       "Input G"
#define LABEL_OUTPUT_GROUP      "Output G"

#define LABEL_MIXER             "Mixer"
#define LABEL_HOME              "Home"

#define LABEL_FREQ              "Freq"
#define LABEL_Q_VALUE           "Q"
#define LABEL_GAIN              "Gain"
#define LABEL_TYPE              "Type"
#define LABEL_BYPASS            "Bypass"
#define LABEL_UNBYPASS          "Unbypass"
#define LABEL_RESET             "Reset"

#define LABEL_NOISE_GATE        "NoiseGate"
#define LABEL_EQUALIZER         "EQ"
#define LABEL_DELAY             "Delay"

#define LABEL_THRESHOLD         "Threshold"
#define LABEL_ATTACK            "Attack"
#define LABEL_DECAY             "Decay"
#define LABEL_RATIO             "Ratio"

// PEQ Type
#define LABEL_PEQ               "PEQ"
#define LABEL_LSEQ              "LSEQ"
#define LABEL_HSEQ              "HSEQ"
#define LABEL_ALLPASS_1         "ALLPASS-1"
#define LABEL_ALLPASS_2         "ALLPASS-2"

// Compressor, limiter
#define LABEL_COMPRESSOR        "Compressor"
#define LABEL_LIMITER           "Limiter"
#define LABEL_DYNAMIC_PROCESSOR "DynamicX"

// PF
#define LABEL_XOVER             "Xover"
#define LABEL_HPF               "HPF"
#define LABEL_LPF               "LPF"
#define LABEL_SLOPE             "Slope"
#define LABEL_BESSEL            "Bessel"
#define LABEL_BUTTER_WORTH      "ButterW"
#define LABEL_LINKWITZ_RILEY    "LinkWitz"


// Unit
#define LABEL_FREQ_UNIT         "Hz"
#define LABEL_TIME_MS_UNIT      "ms"
#define LABEL_DECIBEL_UINT      "dB"
#define LABEL_METER_UINT        "M"
#define LABEL_FOOT_UINT         "ft"



// 11段EQ
constexpr int EQ_11_FREQUENCY_SIZE = 11;
constexpr std::array<uint16_t, EQ_11_FREQUENCY_SIZE> EQ_11_FREQUENCY
{
    50, 100, 160, 250, 500, 1000, 1600, 2500, 5000, 8000, 10000
};

// 15段EQ
constexpr int EQ_15_FREQUENCY_SIZE = 15;
constexpr std::array<uint16_t, EQ_15_FREQUENCY_SIZE> EQ_15_FREQUENCY
{
    25, 40, 63, 100, 160, 250, 400, 630, 1000, 1600, 2500, 4000, 6300, 10000, 16000
};

// 31段EQ
constexpr int EQ_31_FREQUENCY_SIZE = 31;
constexpr std::array<uint16_t, 31> EQ_31_FREQUENCY
{
    20, 25, 31, 40, 50, 63, 80,
    100, 125, 160, 200, 250, 315, 400, 500, 630, 800,
    1000, 1250, 1600, 2000, 2500, 3150, 4000, 5000, 6300, 8000,
    10000, 12500, 16000, 20000
};

// 频率辅助线
constexpr std::array<int, 28> EQ_FREQUENCY_AUX
{
    20, 30, 40, 50, 60, 70, 80, 90, 100,
    200, 300, 400, 500, 600, 700, 800, 900, 1000,
    2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000,
    20000
};

// 绘制标签频率值
constexpr std::array<int, 10> EQ_FREQUENCY_LABEL
{
    20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000
};

// 均衡器频率（画图使用）
constexpr int EQ_FREQUENCY_COUNT = 241;
constexpr std::array<double, EQ_FREQUENCY_COUNT> EQ_FREQUENCY
{
    19.7,   20.3,   20.9,   21.5,   22.1,   22.7,   23.4,   24.1,
    24.8,   25.5,   26.3,   27.0,   27.8,   28.7,   29.5,   30.4,
    31.3,   32.2,   33.1,   34.1,   35.1,   36.1,   37.2,   38.3,
    39.4,   40.5,   41.7,   42.9,   44.2,   45.5,   46.8,   48.2,
    49.6,   51.1,   52.6,   54.1,   55.7,   57.3,   59.0,   60.7,
    62.5,   64.3,   66.2,   68.2,   70.2,   72.2,   74.3,   76.5,
    78.7,   81.1,   83.4,   85.9,   88.4,   91.0,   93.6,   96.4,
    99.2,   102,    105,    108,    111,    115,    118,    121,
    125,    129,    132,    136,    140,    144,    149,    153,
    158,    162,    167,    172,    179,    182,    187,    193,
    198,    204,    210,    216,    223,    229,    236,    243,
    250,    257,    265,    273,    281,    289,    297,    306,
    315,    324,    334,    344,    354,    364,    375,    386,
    397,    409,    420,    433,    445,    459,    472,    486,
    500,    515,    530,    545,    561,    578,    595,    612,
    630,    648,    667,    687,    707,    728,    749,    771,
    794,    817,    841,    866,    891,    917,    944,    972,
    1000,   1030,   1060,   1090,   1123,   1155,   1190,   1224,
    1260,   1297,   1335,   1374,   1414,   1456,   1498,   1542,
    1587,   1634,   1682,   1731,   1782,   1834,   1888,   1943,
    2000,   2059,   2119,   2181,   2245,   2311,   2378,   2448,
    2520,   2594,   2670,   2748,   2828,   2911,   2997,   3084,
    3175,   3268,   3364,   3462,   3564,   3668,   3776,   3886,
    4000,   4117,   4238,   4362,   4490,   4621,   4757,   4896,
    5000,   5187,   5339,   5496,   5657,   5823,   5993,   6169,
    6350,   6536,   6727,   6924,   7127,   7336,   7551,   7772,
    8000,   8234,   8476,   8724,   8980,   9243,   9514,   9792,
    10079,  10374,  10679,  10992,  11314,  11645,  11987,  12338,
    12699,  13071,  13454,  13849,  14254,  14672,  15102,  15545,
    16000,  16469,  16951,  17448,  17959,  18486,  19027,  19585,
    20000
};

// 均衡器Q值
constexpr int EQ_Q_COUNT = 300;
constexpr std::array<double, EQ_Q_COUNT> EQ_Q
{
    144.3, 72.13, 48.09, 36.07,                                                                 // 0.01~0.04
    28.852, 24.043, 20.608, 18.031, 16.027, 14.424,                                             // 0.05~0.10
    13.112, 12.019, 11.094, 10.301, 9.614, 9.012, 8.482, 8.010, 7.588, 7.208, 6.864, 6.551,		// 0.11~0.22

    6.266, 6.004, 5.764, 5.541, 5.336, 5.144, 4.966, 4.800, 4.645, 4.499, 4.362, 4.233, 4.112,	// 0.23~0.35
    3.997, 3.889, 3.786, 3.688, 3.595, 3.507, 3.423, 3.343, 3.266, 3.193, 3.123, 3.056, 2.992,	// 0.36~0.48
    2.930, 2.871, 2.814, 2.759, 2.707, 2.656, 2.607, 2.560, 2.515, 2.471, 2.428, 2.387, 2.348,	// 0.49~0.61
    2.309, 2.272, 2.236, 2.201, 2.167, 2.134, 2.102, 2.071, 2.041, 2.012, 1.983, 1.955, 1.928,	// 0.62~0.74
    1.902, 1.877, 1.852, 1.827, 1.804, 1.780, 1.758, 1.736, 1.714, 1.693, 1.673, 1.653, 1.633,	// 0.75~0.87
    1.614, 1.596, 1.577, 1.559, 1.542, 1.525, 1.508, 1.492, 1.475, 1.460, 1.444, 1.429, 1.414,	// 0.88~1.00
    1.400, 1.385, 1.371, 1.358, 1.344, 1.331, 1.318, 1.305, 1.293, 1.280, 1.268, 1.256, 1.245,	// 1.01~1.13
    1.233, 1.222, 1.211, 1.200, 1.189, 1.179, 1.168, 1.158, 1.148, 1.138, 1.128, 1.119, 1.109,	// 1.14~1.26
    1.100, 1.091, 1.082, 1.073, 1.064, 1.056, 1.047, 1.039, 1.031, 1.023, 1.015, 1.007, 0.999,	// 1.27~1.39

    0.991, 0.984, 0.976, 0.969, 0.961, 0.954, 0.947, 0.940, 0.933, 0.927, 0.920, 0.913, 0.907,	// 1.40~1.52
    0.900, 0.894, 0.887, 0.881, 0.875, 0.869, 0.863, 0.857, 0.851, 0.845, 0.840, 0.834, 0.828,	// 1.53~1.65
    0.823, 0.817, 0.812, 0.807, 0.801, 0.796, 0.791, 0.786, 0.781, 0.776, 0.771, 0.766, 0.761,	// 1.66~1.78
    0.757, 0.752, 0.747, 0.742, 0.738, 0.733, 0.729, 0.724, 0.720, 0.716, 0.711, 0.707, 0.703,	// 1.79~1.91
    0.699, 0.695, 0.690, 0.686, 0.682, 0.678, 0.674, 0.671, 0.667, 0.663, 0.659, 0.655, 0.652,	// 1.92~2.04
    0.648, 0.644, 0.641, 0.637, 0.633, 0.630, 0.626, 0.623, 0.620, 0.616, 0.613, 0.609, 0.606,	// 2.05~2.17
    0.603, 0.600, 0.596, 0.593, 0.590, 0.587, 0.584, 0.581, 0.577, 0.574, 0.571, 0.568, 0.565,	// 2.18~2.30
    0.563, 0.560, 0.557, 0.554, 0.551, 0.548, 0.545, 0.543, 0.540, 0.537, 0.534, 0.532, 0.529,	// 2.31~2.43
    0.526, 0.524, 0.521, 0.518, 0.516, 0.513, 0.511, 0.508, 0.506, 0.503, 0.501, 0.498, 0.496,	// 2.44~2.56
    0.493, 0.491, 0.489, 0.486, 0.484, 0.482, 0.479, 0.477, 0.475, 0.473, 0.470, 0.468, 0.466,	// 2.57~2.69
    0.464, 0.461, 0.459, 0.457, 0.455, 0.453, 0.451, 0.449, 0.447, 0.445, 0.442, 0.440, 0.438,	// 2.70~2.82
    0.436, 0.434, 0.432, 0.430, 0.428, 0.427, 0.425, 0.423, 0.421, 0.419, 0.417, 0.415, 0.413,	// 2.83~2.95
    0.411, 0.410, 0.408, 0.406, 0.404															// 2.96~3.00
};

/*!
 *  @brief freq 频率
 */
// 默认
constexpr uint16_t EQ_FREQUENCY_DEFAULT = 25;
// 最小值
constexpr uint16_t EQ_FREQUENCY_MIN = 20;
// 最大值
constexpr uint16_t EQ_FREQUENCY_MAX = 20000;

/*!
 *  @brief Q
 */
// 默认值（BW = 0.33）
constexpr double EQ_Q_DEFAULT = 4.362;
constexpr int EQ_BW_MIN = 0;
constexpr int EQ_BW_MAX = 299;
// BW EQ_Q位置
constexpr int EQ_BW_DEFAULT = 32;
// 小数位
constexpr int EQ_Q_DECIMAL = 3;

/*!
 *  @brief EQ Gain 增益
 */
// 默认
constexpr double EQ_GAIN_DEFAULT = 0.0;
// 最小值
constexpr double EQ_GAIN_MIN = -24.0;
// 最大值
constexpr double EQ_GAIN_MAX = 12.0;
// 范围长度
constexpr double EQ_GAIN_LENGTH = EQ_GAIN_MAX - EQ_GAIN_MIN;
// 步进
constexpr double EQ_GAIN_STEP = 0.1;
// 小数位
constexpr int EQ_GAIN_DECIMAL = 1;
// 标签步进
constexpr int EQ_GAIN_LABEL_STEP = 6;


// Gain
constexpr double GAIN_MIN = -80.0;
constexpr double GAIN_DEFAULT = 0.0;
constexpr double GAIN_STEP = 0.1;
constexpr int GAIN_DECIMAL = 1;

// Delay
constexpr double DELAY_MIN = 0.0;
constexpr double DELAY_DEFAULT = 0.0;
constexpr int DELAY_DECIMAL = 3;
constexpr double DELAY_METER_RATIO = 0.34;
constexpr double DELAY_FOOT_RATIO = 1.115486;

// NoiseGate
constexpr int NOISE_GATE_THRESHOLD_MIN = -80;
constexpr int NOISE_GATE_THRESHOLD_MAX = -30;
constexpr int NOISE_GATE_THRESHOLD_DEFAULT = -75;
constexpr int NOISE_GATE_THRESHOLD_LENGTH = NOISE_GATE_THRESHOLD_MAX - NOISE_GATE_THRESHOLD_MIN;

// Limiter, Compressor
// Threshold
constexpr double DYNAMIC_X_THRESHOLD_MIN = -48.0;
constexpr double DYNAMIC_X_THRESHOLD_DEFAULT = 0.0;
constexpr double DYNAMIC_X_THRESHOLD_STEP = 0.1;
constexpr int DYNAMIC_X_THRESHOLD_DECIMAL = 1;
// Attack
constexpr uint16_t DYNAMIC_X_ATTACK_MIN = 1;
constexpr uint16_t DYNAMIC_X_ATTACK_MAX = 200;
constexpr uint16_t DYNAMIC_X_ATTACK_DEFAULT = 3;
// Decay
constexpr uint16_t DYNAMIC_X_DECAY_MIN = 1;
constexpr uint16_t DYNAMIC_X_DECAY_MAX = 5000;
constexpr uint16_t DYNAMIC_X_DECAY_DEFAULT = 200;
// Compressor Ratio
constexpr uint8_t DYNAMIC_X_RATIO_MIN = 1;
constexpr uint8_t DYNAMIC_X_RATIO_MAX = 100;
constexpr uint8_t DYNAMIC_X_RATIO_DEFAULT = 10;
// Mixer
constexpr int MIXER_VOL_MIN  = -100;
constexpr int MIXER_VOL_MAX  = 0;
// Peak
constexpr int PEAK_MIN = -100;
constexpr int PEAK_MAX = 27;
constexpr int PEAK_SCALE_MIN = -60;
constexpr int PEAK_SCALE_MAX = 12;
constexpr int PEAK_SCALE_LENGTH = PEAK_SCALE_MAX - PEAK_SCALE_MIN;
constexpr int PEAK_SCALE_STEP = 6;

/*!
 * @brief EQ type
*/

// HPF LPF
constexpr std::array<const char *, 3> PF_TYPE { LABEL_BESSEL, LABEL_BUTTER_WORTH, LABEL_LINKWITZ_RILEY };
// 0表示关闭滤波器
constexpr std::array<int, 4> PF_TYPE_SLOPE { 12, 24, 36, 48 };

// double 零除
constexpr double EPSILON_10E = 1e-10;
constexpr double EPSILON_12E = 1e-12;

// 声速 340 m/s
constexpr double SOUND_SPEED = 340;

#endif // DMDEF_H
